import request from '@/utils/request'
// import qs from 'qs'

// 告警策略

// 获取日志告警策略信息
export function getLogAlertInfo (params) {
  var data = fromData(params)
  return request({
    url: '/alert/getLogAlertInfo',
    method: 'post',
    data
  })
}

// 获取日志告警策略列表
export function getLogAlertArray (params) {
  var data = fromData(params)
  return request({
    url: '/alert/getLogAlertArray',
    method: 'post',
    data
  })
}

// 获取流量告警策略
export function getFlowAlertInfo (params) {
  var data = fromData(params)
  return request({
    url: '/alert/getFlowAlertInfo',
    method: 'post',
    data
  })
}

// 获取系统告警策略信息
export function getSysAlertInfo (params) {
  var data = fromData(params)
  return request({
    url: '/alert/getSysAlertInfo',
    method: 'post',
    data
  })
}

// 获取系统告警策略列表
export function getSysAlertArray (params) {
  var data = fromData(params)
  return request({
    url: '/alert/getSysAlertArray',
    method: 'post',
    data
  })
}

// 设置日志告警策略信息
export function setLogAlert (params) {
  var data = fromData(params)
  return request({
    url: '/alert/setLogAlert',
    method: 'post',
    data
  })
}

// 设置流量告警策略
export function setFlowAlert (params) {
  var data = fromData(params)
  return request({
    url: '/alert/setFlowAlert',
    method: 'post',
    data
  })
}

// 设置系统告警策略信息
export function setSysAlert (params) {
  var data = fromData(params)
  return request({
    url: '/alert/setSysAlert',
    method: 'post',
    data
  })
}

// 设置流量告警策略 1.0.1版本
export function editFlowAlert (params) {
  var data = fromData(params)
  return request({
    url: '/alert/editFlowAlert',
    method: 'post',
    data
  })
}

// 获取统计告警策略信息
export function getStatisticsAlertInfo (params) {
  var data = fromData(params)
  return request({
    url: '/alert/getStatisticsAlertInfo',
    method: 'post',
    data
  })
}

// 设置统计告警策略信息
export function setStatisticsAlert (params) {
  var data = fromData(params)
  return request({
    url: '/alert/setStatisticsAlert',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
